package com.carlinfo.back.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 不需要登录就可以访问的页面
 */
public class NoLoginBackServlet extends HttpServlet
{
	private Logger logger = LogManager.getLogger();

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		logger.info("==NoLoginBackServlet=service=");
		/*取信的内容;去单个
		 * 
		 * */
		String method = request.getParameter("method");
		logger.info("==method:{}==",method);
		if("login".equalsIgnoreCase(method))
		{
			/* 打开登录页面 */
			this.login(request,response);
		}else if("loginSubmit".equalsIgnoreCase(method))
		{
			/* 登陆提交操作 */
			this.loginSubmit(request,response);
		}
	}

	/**
	 * 打开登陆页面
	 * 
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException
	 */
	private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		logger.info("==login==");
		/* 打开登陆页 */
		String path = "/WEB-INF/jsp/back/login.jsp";
		/* 服务器端跳转 */
		request.getRequestDispatcher(path).forward(request, response);
	}

	private void loginSubmit(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
		logger.info("==loginSubmit==");
		/* 打开登陆页 */
		String path = request.getContextPath() + "/back/AdminsBackServlet?method=main";
		/* 登陆成功;
		 * 客户端跳转
		 *  */
		response.sendRedirect(path);
	}
}
